package com.ksyun.campus.metaserver.domain.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Standard API response
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> {
    
    private boolean ok;
    private String message;
    private T data;
    private String code;
    private String leader; // for NOT_LEADER responses
    
    public static <T> ApiResponse<T> success(T data) {
        return ApiResponse.<T>builder()
                .ok(true)
                .data(data)
                .build();
    }
    
    public static <T> ApiResponse<T> success() {
        return ApiResponse.<T>builder()
                .ok(true)
                .build();
    }
    
    public static <T> ApiResponse<T> error(String message) {
        return ApiResponse.<T>builder()
                .ok(false)
                .message(message)
                .build();
    }
    
    public static <T> ApiResponse<T> notLeader(String leader) {
        return ApiResponse.<T>builder()
                .ok(false)
                .code("NOT_LEADER")
                .leader(leader)
                .message("Current node is not leader")
                .build();
    }
}
